﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildCreatePanel extends GuildOtherBasePanel
    {
        private var _txtInputGuildName:GTextInput;
        private var _txtInputGuildPurpose:GTextInput;
        private var _radioButtonCreateByYuanBao:GRadioButton;
        private var _radioButtonCreateByFree:GRadioButton;
        private var _btnCreateGuild:GButton;
        private var _moneyTxt:GTextFiled;
        private var _freeVipL:int = 3;
        private static var _instance:GuildCreatePanel = null;

        public function GuildCreatePanel(param1:ILayer = null)
        {
            super(param1);
            setSize(280, 290);
            title = "" + Language.getString(71149);
            return;
        }// end function

        override public function layoutUI() : void
        {
            UIFactory.gTextField(Language.getString(60046), 116, 36, 60, 20, this, GlobalStyle.textFormatJiang);
            this._txtInputGuildName = UIFactory.gTextInput(24, 55, 240, 24, this);
            this._txtInputGuildName.text = Language.getString(60063);
            this._txtInputGuildName.maxChars = 14;
            UIFactory.gTextField(Language.getString(60006), 116, 85, 60, 20, this, GlobalStyle.textFormatJiang);
            this._txtInputGuildPurpose = UIFactory.gTextInput(24, 104, 240, 84, this);
            this._txtInputGuildPurpose.text = Language.getString(60064);
            this._txtInputGuildPurpose.maxChars = 50;
            this._radioButtonCreateByYuanBao = UIFactory.radioButton(Language.getString(60055), 24, 196, 50, 20);
            this._radioButtonCreateByYuanBao.groupName = "createGuild";
            this._moneyTxt = UIFactory.gTextField("", 70, 196, 140, 20);
            this._radioButtonCreateByFree = UIFactory.radioButton(Language.getStringByParam(71150, GuildListPanel.FreeCreateGuildVipLv), 24, 218, 150, 20, this);
            this._radioButtonCreateByFree.groupName = "createGuild";
            this._btnCreateGuild = UIFactory.gButton(Language.getString(60047), 112, 257, 67, 22, this);
            this.setMoneyTxt();
            NetDispatcher.addCmdListener(ServerCommand.GUILD_CREATE_FAIL, this.setMoneyTxt);
            this._radioButtonCreateByFree.selected = true;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.GUILD_CREATE_FAIL, this.setMoneyTxt);
            this._txtInputGuildName = null;
            this._txtInputGuildPurpose = null;
            this._radioButtonCreateByYuanBao = null;
            this._radioButtonCreateByFree = null;
            this._btnCreateGuild = null;
            this._moneyTxt = null;
            return;
        }// end function

        private function setMoneyTxt(param1:Object = null) : void
        {
            var _loc_2:String = null;
            if (Cache.instance.guild.freeCreateGuildNum < GuildNewUtil.freeGuildNum)
            {
                this._radioButtonCreateByYuanBao.label = "";
                this._moneyTxt.x = 42;
                this._moneyTxt.htmlText = Language.getStringByParam(70543, GuildNewUtil.freeGuildNum - Cache.instance.guild.freeCreateGuildNum);
            }
            else
            {
                _loc_2 = "<font color=\'#ffcc00\'>" + "VIP2可" + GuildConst.CreateGuildRequireCostGold + "钻石</font><font color=\'#ffffff\'>" + Language.getString(60056) + "</font>";
                this._radioButtonCreateByYuanBao.label = Language.getString(60055);
                this._moneyTxt.x = 70;
                this._moneyTxt.htmlText = _loc_2;
            }
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_3:RegExp = null;
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_6:Object = null;
            switch(event.target)
            {
                case this._btnCreateGuild:
                {
                    if (!this._radioButtonCreateByYuanBao.selected && !this._radioButtonCreateByFree.selected)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71151));
                        return;
                    }
                    if (VipUtil.vipLevel < GuildListPanel.FreeCreateGuildVipLv)
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(71152, GuildListPanel.FreeCreateGuildVipLv));
                        return;
                    }
                    if (this._radioButtonCreateByYuanBao.selected)
                    {
                        _loc_2 = Cache.instance.guild.freeCreateGuildNum < GuildNewUtil.freeGuildNum ? (ECreate._ECreateFirst2Times) : (ECreate._ECreateMoney);
                    }
                    else
                    {
                        _loc_2 = ECreate._ECreateNoMoney;
                    }
                    _loc_3 = /\S""\S/;
                    _loc_4 = this._txtInputGuildName.text != Language.getString(60063) ? (this._txtInputGuildName.text) : ("");
                    if (_loc_4.match(_loc_3) == null)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71153));
                        return;
                    }
                    if (_loc_4.length > this._txtInputGuildName.maxChars)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71154));
                        return;
                    }
                    _loc_4 = FilterText.instance.getFilterStr(_loc_4);
                    if (_loc_4.indexOf("*") != -1)
                    {
                        this._txtInputGuildName.text = _loc_4;
                        this._txtInputGuildName.setStyle("textFormat", GlobalStyle.textFormatItemRed);
                        MsgManager.showRollTipsMsg("" + Language.getString(71155));
                        return;
                    }
                    if (ECreate._ECreateNoMoney == _loc_2 && VipUtil.vipLevel < GuildListPanel.FreeCreateGuildVipLv)
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(71156, GuildListPanel.FreeCreateGuildVipLv));
                        return;
                    }
                    _loc_5 = this._txtInputGuildPurpose.text != Language.getString(60064) ? (this._txtInputGuildPurpose.text) : ("");
                    _loc_6 = new Object();
                    _loc_6.type = _loc_2;
                    _loc_6.name = _loc_4;
                    _loc_6.purpose = _loc_5;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_CREATE, _loc_6));
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (event.target.parent && event.target.parent is GTextInput)
            {
                switch(event.target.parent)
                {
                    case this._txtInputGuildName:
                    {
                        if (this._txtInputGuildName.text == Language.getString(60063))
                        {
                            this._txtInputGuildName.text = "";
                        }
                        break;
                    }
                    case this._txtInputGuildPurpose:
                    {
                        if (this._txtInputGuildPurpose.text == Language.getString(60064))
                        {
                            this._txtInputGuildPurpose.text = "";
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        public static function get instance() : GuildCreatePanel
        {
            if (!_instance)
            {
                _instance = new GuildCreatePanel;
            }
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
